package com.wn.controller.demo;


import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

// 配置类
@Configuration
// 读取配置文件填充到指定类型的对象中，且加入容器
@EnableConfigurationProperties({JdbcProperties.class})
public class JdbcConfig {

    @Autowired
    private JdbcProperties jdbcProperties;

    @Bean
    public DataSource dataSource(){
        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName(jdbcProperties.getDriver());
        ds.setUrl(jdbcProperties.getUrl());
        ds.setPassword(jdbcProperties.getPassword());
        ds.setUsername(jdbcProperties.getUsername());
        return ds;
    }

}
